var t, a = require("../../../@babel/runtime/helpers/toConsumableArray"), e = require("../../../@babel/runtime/helpers/typeof"), i = require("../../../@babel/runtime/helpers/defineProperty"), n = require("../../../utils/themeSkin/skinBehavior"), o = require("../../../ec-canvas/echarts"), s = getApp();

Page({
    behaviors: [ n ],
    data: (t = {
        themeStyle: null,
        language: "",
        invalid: 0,
        expect: 0,
        unliquidated: 0,
        liquidated: 0,
        not_yet_withdrawed: 0,
        withdrawed: 0,
        manage: 0,
        is_manage: "",
        count: 0,
        distrbution_name: "",
        distrbution_tiem: "",
        second_level: 0,
        third_level: 0,
        userName: "",
        vipId: "",
        userAvatar: "",
        mailLanguage: "",
        ecIncome: {
            lazyLoad: !0
        },
        ecFans: {
            lazyLoad: !0
        },
        plugin_data: null,
        first_level: 0
    }, i(t, "count", 0), i(t, "searchKey", ""), i(t, "order_status", null), i(t, "Commission_status", null), 
    i(t, "option1", [ {
        text: "请选择",
        value: 0
    }, {
        text: "待付款",
        value: 1
    }, {
        text: "待发货",
        value: 2
    }, {
        text: "待收货",
        value: 3
    }, {
        text: "已完成",
        value: 4
    }, {
        text: "已关闭",
        value: 5
    } ]), i(t, "option2", [ {
        text: "请选择",
        value: 0
    }, {
        text: "预计佣金",
        value: 1
    }, {
        text: "未结算",
        value: 2
    }, {
        text: "已结算",
        value: 3
    }, {
        text: "未提现",
        value: 4
    }, {
        text: "已提现",
        value: 5
    }, {
        text: "无效",
        value: 6
    } ]), i(t, "show", !1), i(t, "openStop", !1), i(t, "boxShow", !1), i(t, "agent_level", []), 
    t),
    onLoad: function(t) {
        var a = this;
        try {
            var i = function() {
                var t = JSON.parse(wx.getStorageSync("mailLanguage")), e = wx.getStorageSync("langIndex");
                a.setData({
                    language: e.en,
                    mailLanguage: t.commission
                }), wx.setNavigationBarTitle({
                    title: t.commission.agent ? t.commission.agent : "分销商"
                });
                for (var i = wx.getStorageSync("yz_basic_info"), n = i.popularize_page.mini.vue_route, o = 0; o < n.length; o++) if ("distribution" == n[o]) return console.log(i.popularize_page.mini.mini_url + "跳转的路径"), 
                wx.showToast({
                    title: "未开启推广权限",
                    duration: 1e3,
                    icon: "none",
                    success: function() {
                        setTimeout(function() {
                            wx.redirectTo({
                                url: i.popularize_page.mini.mini_url
                            });
                        }, 1e3);
                    }
                }), {
                    v: void 0
                };
            }();
            if ("object" === e(i)) return i.v;
        } catch (t) {
            console.log(t);
        }
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
        var a = wx.getStorageSync("yz_basic_info").theme_color;
        this.setData({
            basicColor: a
        });
    },
    onShow: function() {
        this.getData(), this.getcommissionOrders();
    },
    changeStatus: function(t) {
        console.log(t, "dddddd");
        var a = t.detail;
        this.setData({
            order_status: a
        });
    },
    btnSearch: function() {
        this.data.Commission_record = [], this.getcommissionOrders();
    },
    changeStatus2: function(t) {
        var a = t.detail;
        this.setData({
            Commission_status: a
        });
    },
    tabChange: function(t) {
        var a, e;
        if ("fans_type" === (a = t.currentTarget.dataset.type)) e = t.detail.index, this.setData({
            fans_type: e
        }), this.getFans(e); else if ("recordType" === a) {
            var i = t.detail.index;
            this.setData({
                recordType: i,
                Commission_record: [],
                extension_order: []
            }), 0 == i ? this.getcommissionOrders() : 1 == i && this.getFansRecord(i);
        }
    },
    getcommissionOrders: function() {
        var t = this, a = {
            search: this.data.searchKey,
            commission_type: this.data.Commission_status,
            order_status: this.data.order_status
        }, e = s.getNetAddresss("plugin.commission.api.new-commission.get-commission-orders");
        s._getNetWork({
            url: e,
            data: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    Commission_record: e.data.orders,
                    Commission_record_set: e.data.set,
                    isLoadMore: !0
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getFansRecord: function(t) {
        var a = this;
        this.data.isLoadMore = !1;
        var e = s.getNetAddresss("finance.income-page.extension");
        s._getNetWork({
            url: e,
            data: {
                extension_type: t
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    extension_order: e.data,
                    isLoadMore: !0
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    toWithrawal: function() {
        wx.navigateTo({
            url: "/packageA/member/withdrawal/withdrawal"
        });
    },
    toastMethod: function(t) {
        var a = "", e = t.currentTarget.dataset.type;
        0 != e ? (1 == e ? a = "直推客户购买的订单总额" : 2 == e ? a = "累计分销".concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "=预计").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "+未结算").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "+已结算").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "，不含无效").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "，因预计").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "可能会变成无效").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "，故累计").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "数据会有所变化") : 3 == e ? a = "客户下单后根据设置计算的推广者预计获得的".concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "，并非实际获得").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "，如订单退款关闭则变更为无效").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "。") : 4 == e ? a = "客户订单完成后，获得未结算".concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "，满足结算期即可变更为结算").concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金") : 5 == e && (a = "客户订单完成并满足结算期后推广者实际获得的".concat(this.data.mailLanguage.commission ? mailLanguage.commission : "佣金", "。")), 
        wx.showModal({
            title: a,
            showCancel: !1
        })) : this.gomyRelationship();
    },
    getFans: function(t) {
        var a = this, e = s.getNetAddresss("finance.income-page.fans-charts");
        s._getNetWork({
            url: e,
            data: {
                charts_type: t
            },
            success: function(e) {
                var i = e.data;
                1 == i.result ? (a.setData({
                    fans_fission: i.data
                }), 1 == t ? a.initOrderEcharts() : a.initFansEcharts()) : wx.showToast({
                    title: i.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    initOrderEcharts: function() {
        var t = this.selectComponent("#echats-fans-line"), e = Math.max.apply(Math, a(this.data.fans_fission.orderCountSeries)) || 50, i = Math.max.apply(Math, a(this.data.fans_fission.orderPriceSeries)) || 50, n = e / 5 || 5, s = i / 5 || 5, r = {
            tooltip: {
                trigger: "axis",
                axisPointer: {
                    type: "cross",
                    crossStyle: {
                        color: "#999"
                    }
                }
            },
            toolbox: {
                feature: {
                    magicType: {
                        show: !0,
                        type: [ "line", "bar" ]
                    },
                    saveAsImage: {
                        show: !0
                    }
                }
            },
            legend: {
                data: [ "订单金额", "订单数量" ]
            },
            xAxis: {
                type: "category",
                boundaryGap: !1,
                data: this.data.fans_fission.x_axis,
                axisPointer: {
                    type: "shadow"
                }
            },
            yAxis: [ {
                type: "value",
                name: "订单金额",
                min: 0,
                max: i,
                interval: s
            }, {
                type: "value",
                name: "订单数量",
                min: 0,
                max: e,
                interval: n
            } ],
            series: [ {
                name: "订单金额",
                type: "bar",
                color: "#f19c70",
                data: this.data.fans_fission.orderPriceSeries
            }, {
                name: "订单数量",
                type: "line",
                yAxisIndex: 1,
                color: "#77c399",
                data: this.data.fans_fission.orderCountSeries
            } ]
        };
        t.init(function(t, a, e) {
            var i = o.init(t, null, {
                width: a,
                height: e
            });
            return i.setOption(r), i;
        });
    },
    initFansEcharts: function() {
        var t = this.selectComponent("#echats-fans");
        console.log(t);
        var e = Math.max.apply(Math, a(this.data.fans_fission.totalFansSeries)) || 50, i = Math.max.apply(Math, a(this.data.fans_fission.fansNewSeries)) || 50, n = e / 5 || 5, s = i / 5 || 5, r = {
            tooltip: {
                trigger: "axis",
                axisPointer: {
                    type: "cross",
                    crossStyle: {
                        color: "#999"
                    }
                }
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            legend: {
                data: [ "粉丝总数", "单日新增粉丝" ]
            },
            xAxis: {
                type: "category",
                boundaryGap: !1,
                data: this.data.fans_fission.x_axis,
                axisPointer: {
                    type: "shadow"
                }
            },
            yAxis: [ {
                type: "value",
                name: "总数",
                min: 0,
                max: e,
                interval: n
            }, {
                type: "value",
                name: "单日",
                min: 0,
                max: i,
                interval: s
            } ],
            series: [ {
                name: "粉丝总数",
                type: "line",
                color: "#77c399",
                data: this.data.fans_fission.totalFansSeries
            }, {
                name: "单日新增粉丝",
                type: "line",
                yAxisIndex: 1,
                color: "#f19c70",
                data: this.data.fans_fission.fansNewSeries
            } ]
        };
        t.init(function(t, a, e) {
            var i = o.init(t, null, {
                width: a,
                height: e
            });
            return i.setOption(r), i;
        });
    },
    toggle: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.id;
        this.data.display != a ? this.setData({
            display: a
        }) : this.setData({
            display: ""
        });
    },
    pluginGoto: function(t) {
        var a = t.currentTarget.dataset.item, e = a.url;
        "courier" == a.name ? (wx.setStorage({
            key: "couriername",
            data: a.title
        }), wx.navigateTo({
            url: "/packageA/member/" + e + "/" + e
        })) : "HotelManage" == a.url ? wx.navigateTo({
            url: "/packageA/hotel/HotelManage/HotelManage?title=" + encodeURIComponent("酒店管理")
        }) : "cloudIndex" == a.url ? wx.navigateTo({
            url: "/packageE/others/cloudwarehouse/cloud_index/cloud_index"
        }) : "collageIndex" == a.url ? wx.navigateTo({
            url: "/packageE/member/collage/collageIndex/collageIndex"
        }) : "m-erweima" == a.name ? this.openQrCode(this.data.dataIs) : a.mini_url && wx.navigateTo({
            url: a.mini_url
        });
    },
    touchstart1: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getMoreData();
    },
    getMoreData: function() {
        var t = this, a = "", e = {};
        if (this.data.isLoadMore) {
            if (1 == this.data.recordType) {
                if (this.data.extension_order.current_page >= this.data.extension_order.last_page) return void (this.data.isLoadMore = !1);
                a = s.getNetAddresss("finance.income-page.extension"), this.data.extension_order.current_page += 1, 
                e = {
                    page: this.data.extension_order.current_page,
                    extension_type: this.data.recordType
                }, wx.showLoading({
                    title: "加载中"
                });
            } else {
                if (this.data.Commission_record.current_page >= this.data.Commission_record.last_page) return void (this.data.isLoadMore = !1);
                this.data.Commission_record.current_page += 1, e = {
                    search: this.data.searchKey,
                    commission_type: this.data.Commission_status,
                    order_status: this.data.order_status,
                    page: this.data.Commission_record.current_page
                }, a = s.getNetAddresss("plugin.commission.api.new-commission.get-commission-orders"), 
                wx.showLoading({
                    title: "加载中"
                });
            }
            this.data.isLoadMore = !1, s._getNetWork({
                url: a,
                data: e,
                success: function(a) {
                    wx.hideLoading({
                        success: function(t) {}
                    }), t.data.isLoadMore = !0;
                    var e = a.data;
                    if (1 == e.result) if (1 == t.data.recordType) {
                        var i = e.data.data;
                        t.setData({
                            "extension_order.data": t.data.extension_order.data.concat(i)
                        });
                    } else {
                        var n = e.data.orders.data;
                        t.setData({
                            "Commission_record.data": t.data.Commission_record.data.concat(n)
                        });
                    }
                },
                fail: function(t) {
                    wx.hideLoading({
                        success: function(t) {}
                    });
                }
            });
        }
    },
    onShareAppMessage: function() {},
    _getDistributionCommissionData: function() {
        var t = this, a = s.getNetAddresss("plugin.commission.api.commission.get-commission");
        s._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                1 == e.result && (t.setDistributionCommissionData(e.data), t.setData({
                    invalid: e.data.invalid
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    setDistributionCommissionData: function(t) {
        this.setData({
            expect: t.expect,
            unliquidated: t.unliquidated,
            liquidated: t.liquidated,
            not_yet_withdrawed: t.not_yet_withdrawed,
            withdrawed: t.withdrawed,
            manage: t.manage
        }), this.data.is_manage = "1" == t.is_manage;
    },
    _getAgentCountData: function() {
        var t = this, a = s.getNetAddresss("member.member.getMyAgentCount");
        s._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                1 == e.result && t.setAgentCountData(e.data);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    setAgentCountData: function(t) {
        this.setData({
            count: t.count
        });
    },
    _getLevelData: function() {
        var t = this, a = s.getNetAddresss("plugin.commission.api.commission.get-agent-level");
        s._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                1 == e.result && (t.setDistributionInfo(e.data), t.setDistributionScaleInfo(e.data));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    setDistributionInfo: function(t) {
        this.setData({
            distrbution_name: t.name,
            distrbution_tiem: t.created_at
        });
    },
    setDistributionScaleInfo: function(t) {
        this.setData({
            first_level: t.first_level,
            second_level: t.second_level,
            third_level: t.third_level
        });
    },
    getData: function() {
        var t = this, a = s.getNetAddresss("plugin.commission.api.new-commission.get-commission");
        s._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    if (console.log(e.data), !e.data.member.yz_member.is_agent) return void wx.showModal({
                        title: "提示",
                        content: "请先申请成为推广员",
                        success: function(t) {
                            t.confirm ? wx.redirectTo({
                                url: "/packageA/member/extension/ExtensionApply/ExtensionApply"
                            }) : t.cancel && wx.navigateBack({
                                delta: 1
                            });
                        }
                    });
                    wx.setNavigationBarColor({
                        frontColor: "#ffffff",
                        backgroundColor: t.data.themeBaseColor,
                        animation: {
                            duration: 400,
                            timingFunc: "easeIn"
                        }
                    }), console.log(e.data, "ddddddddddd"), t.setData({
                        boxShow: !0,
                        agent_level: e.data.agent_level,
                        userName: e.data.member.nickname,
                        vipId: e.data.member.uid,
                        userAvatar: e.data.member.avatar,
                        commissionArr: e.data.commission,
                        plugin_data: e.data.plugin_data,
                        count: e.data.commission.customer,
                        first_level: Number(e.data.agent_level.first_level)
                    }), t.tabChange({
                        currentTarget: {
                            dataset: {
                                type: "fans_type"
                            }
                        },
                        detail: {
                            index: ""
                        }
                    });
                } else {
                    if ("该会员不是推广员" == e.msg) return void wx.showModal({
                        title: "提示",
                        content: "请先申请成为推广员",
                        success: function(t) {
                            t.confirm ? wx.redirectTo({
                                url: "/packageA/member/extension/ExtensionApply/ExtensionApply"
                            }) : t.cancel && wx.navigateBack({
                                delta: 1
                            });
                        }
                    });
                    s.tips(e.msg);
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    gomyRelationship: function() {
        wx.navigateTo({
            url: "/packageD/member/myRelationship/myRelationship"
        });
    },
    msg: function() {
        wx.showToast({
            icon: "none",
            title: "因商品、供应商可以独立设置佣金，您最终获得的佣金可能与此比例不同",
            duration: 3e3
        });
    },
    openDrop: function(t) {
        this.setData({
            openStop: !0
        });
    },
    closeDrop: function() {
        this.setData({
            openStop: !1
        });
    },
    onClose: function() {
        this.setData({
            show: !1
        });
    },
    showTap: function() {
        this.setData({
            show: !0
        });
    },
    gocommission: function() {
        wx.navigateTo({
            url: "/packageA/member/extension/commission/commission"
        });
    },
    gounsettled: function() {
        wx.navigateTo({
            url: "/packageA/member/extension/unsettled/unsettled"
        });
    },
    goalreadySettled: function() {
        wx.navigateTo({
            url: "/packageA/member/extension/alreadySettled/alreadySettled"
        });
    },
    gonotPresent: function() {
        wx.navigateTo({
            url: "/packageA/member/extension/notPresent/notPresent"
        });
    },
    gopresent: function() {
        wx.navigateTo({
            url: "/packageA/member/extension/present/present?type=0"
        });
    },
    goinvalid: function() {
        wx.navigateTo({
            url: "/packageA/member/extension/present/present?type=1"
        });
    },
    godistributionOrder: function(t) {
        var a = t.currentTarget.dataset.idx;
        wx.navigateTo({
            url: "/packageA/member/extension/distributionOrder/distributionOrder?selected=" + a
        });
    }
});